package com.tys.algorithm.beginner;

import java.util.HashMap;
import java.util.TreeMap;

public class Code10_HashMapTreeMap {

    public static class Node {
        public int value;

        public Node(int v) {
            value = v;
        }
    }

    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("zuochengyun", "我是左程云");
        System.out.println(map.containsKey("zuochengyun"));
        System.out.println(map.containsKey("zuo"));
        System.out.println(map.get("zuochengyun"));

        map.put("zuochengyun", "他是左程云");
        System.out.println(map.get("zuochengyun"));

        map.remove("zuochengyun");
        System.out.println(map.containsKey("zuochengyun"));
        System.out.println(map.get("zuochengyun"));

        String test1 = "zuochengyun";
        String test2 = "zuochengyun";
        System.out.println(map.containsKey(test1));
        System.out.println(map.containsKey(test2));

        HashMap<Integer, String> map2 = new HashMap<>();
        map2.put(1234567, "我是1234567");

        Integer a = 1234567;
        Integer b = 1234567;
        System.out.println(a == b);
        System.out.println(map2.containsKey(a));
        System.out.println(map2.containsKey(b));

        Node node1 = new Node(1);
        Node node2 = new Node(1);
        HashMap<Node, String> map3 = new HashMap<>();
        map3.put(node1, "我进来了");
        System.out.println(map3.containsKey(node1));
        System.out.println(map3.containsKey(node2));

        System.out.println("======================");
        TreeMap<Integer, String> treeMap = new TreeMap<>();
        treeMap.put(3, "我是3");
        treeMap.put(0, "我是3");
        treeMap.put(7, "我是3");
        treeMap.put(2, "我是3");
        treeMap.put(5, "我是3");
        treeMap.put(9, "我是3");

        System.out.println(treeMap.containsKey(7));
        System.out.println(treeMap.containsKey(6));
        treeMap.put(3, "他是3");
        System.out.println(treeMap.get(3));

        treeMap.remove(3);
        System.out.println(treeMap.get(3));

        System.out.println(treeMap.firstKey());
        System.out.println(treeMap.lastKey());
        System.out.println(treeMap.floorKey(5));
        System.out.println(treeMap.floorKey(6));

        System.out.println(treeMap.ceilingKey(5));
        System.out.println(treeMap.ceilingKey(6));

        Node node3 = new Node(3);
        Node node4 = new Node(4);
        TreeMap<Node, String> treeMap2 = new TreeMap<>();
        treeMap2.put(node3, "我是node3");
        treeMap2.put(node4, "我是node4");


    }
}
